// eslint-disable-next-line import/no-extraneous-dependencies
import store from 'storejs';
import router from '../router/index';
// eslint-disable-next-line import/first
import { message } from 'ant-design-vue';

function checkIsLogined() {
  const user = store.get('user');
  return user && user.cookie;
}

router.beforeEach((to, from, next) => {
  // console.log(to.matched[0].meta.requireDailySongs);
  if (to.matched.some(item => item.meta.requireLogin)) {
    if (checkIsLogined()) {
      next();
    } else {
      message.warning('您现在还没有这个权限访问，请登录后再访问该页面');
      router.push({ name: 'account', params: { originRouteName: to.name } });
    }
  } else {
    next();
  }
});

export default router;
